﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UniRx;
using System;

/// <summary>
/// 玩家属性
/// </summary>
public class PlayerAttribute : UnitAttributeBase
{
    #region 属性

    /// <summary>
    /// 最大等级
    /// </summary>
    public ReactiveProperty<int> MaxLevel = new ReactiveProperty<int>();

    /// <summary>
    /// 升级所需经验值
    /// </summary>
    public ReactiveProperty<int> UpgradeExperience = new ReactiveProperty<int>();

    /// <summary>
    /// 当前经验值
    /// </summary>
    public ReactiveProperty<int> CurrentExperience = new ReactiveProperty<int>();

    /// <summary>
    /// 能量（参考剑灵的内力，岛2的sp）
    /// </summary>
    public int energyCapacity { get => m_EnergyCapacity.Value; set => m_EnergyCapacity.Value = value; }
    public IObservable<int> onEnergyCapacity => m_EnergyCapacity;
    private ReactiveProperty<int> m_EnergyCapacity = new ReactiveProperty<int>();

    /// <summary>
    /// 当前能量
    /// </summary>
    public int currentEnergy { get => m_CurrentEnergy.Value; set => m_CurrentEnergy.Value = value; }
    public IObservable<int> onCurrentEnergy => m_CurrentEnergy;
    private ReactiveProperty<int> m_CurrentEnergy = new ReactiveProperty<int>();

    /// <summary>
    /// 体力
    /// </summary>
    public int staminaCapacity { get => m_StaminaCapacity.Value; set => m_StaminaCapacity.Value = value; }
    public IObservable<int> onStaminaCapacity => m_StaminaCapacity;
    private ReactiveProperty<int> m_StaminaCapacity = new ReactiveProperty<int>();

    /// <summary>
    /// 当前体力
    /// </summary>
    public int currentStamina { get => m_CurrentStamina.Value; set => m_CurrentStamina.Value = value; }
    public IObservable<int> onCurrentStamina => m_CurrentStamina;
    private ReactiveProperty<int> m_CurrentStamina = new ReactiveProperty<int>();

    /// <summary>
    /// 氧气
    /// </summary>
    public ReactiveProperty<double> OxygenCapacity = new ReactiveProperty<double>();

    /// <summary>
    /// 当前氧气
    /// </summary>
    public ReactiveProperty<double> CurrentOxygen = new ReactiveProperty<double>();

    /// <summary>
    /// 保暖值（待定）
    /// </summary>
    public ReactiveProperty<double> WarmthCapacity = new ReactiveProperty<double>();

    /// <summary>
    /// 当前保暖
    /// </summary>
    public ReactiveProperty<double> CurrentWarmth = new ReactiveProperty<double>();

    #endregion

    protected override void OnInit()
    {
        // TODO 这里是临时属性，从存档读取
        baseHP = 5;
        energyCapacity = 3;
        staminaCapacity = 10000;
        speed = 1;
        baseAttack = 1;
    }

    protected override void OnSpawn()
    {
        RecoverAttribute();
    }

    private void RecoverAttribute()
    {
        currentHP = totalHP;
        currentEnergy = energyCapacity;
        currentStamina = staminaCapacity;
    }
}